import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReadFile {
    public static void main(String[] args) {
        String filePath = "src/ok.txt"; // 指定文件路径

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            float a = 0;
            int i = 0;
            while ((line = br.readLine()) != null) {
                if (i >=1){
                String b[] = line.split("[，元]");
                a = a + Float.parseFloat(b[1]);
                }
                i+=1;                
            }
            FileWriter writer = new FileWriter(filePath, true);
            writer.write("\n"+"平均价格："+Float.toString(a/i));
            writer.close();
        } catch (IOException e) {
            e.printStackTrace(); // 处理异常
        }
         
        
    }
}

